home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7167 < prev    next >
Encoding:
Text File  |  1996-08-05  |  884 b   |  33 lines

  1. Path: in2.uu.net!usc!usc!not-for-mail
  2. From: wawda@alcor.usc.edu (Abu Wawda)
  3. Newsgroups: comp.lang.c++
  4. Subject: Why Do Return Values Sometimes Have '&' Appended?
  5. Date: 21 Feb 1996 16:15:27 -0800
  6. Organization: University of Southern California, Los Angeles, CA
  7. Sender: wawda@alcor.usc.edu
  8. Distribution: world
  9. Message-ID: <4ggciv$iq1@alcor.usc.edu>
  10. NNTP-Posting-Host: alcor.usc.edu
  11.  
  12. I have seen code where some of the functions are returned with the
  13. reference operator (&) attached to the end. Here is an example:
  14.  
  15. MyReturn& MyFunction(...)
  16. {
  17. }
  18.  
  19. I don't understand what that does. I have seen this most often in
  20. operator overloading such as:
  21.  
  22. class MyClass
  23. {
  24.   MyClass& operator + (MyClass&);
  25. }
  26.  
  27. I understand why you the function parameter uses the & operator since
  28. you want to pass the class by reference, but why is it used in the
  29. return value? Thank you,
  30.  
  31. Abu Wawda
  32. wawda@scf.usc.edu
  33.